package com.funever.fragment;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import com.funever.combworkalerm.R;
import com.funever.entity.Works;
import com.squareup.timessquare.CalendarPickerView;
import com.squareup.timessquare.CalendarPickerView.SelectionMode;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class TypeReviewFragment extends BaseFragment {
	
	CalendarPickerView cpv;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mainView = inflater.inflate(R.layout.type_review_layout, null);
		return mainView;
	}
	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		getActivity().setTitle("班次浏览");
		cpv = (CalendarPickerView) mainView.findViewById(R.id.calendar_view);
		
		List<Works> wl = Works.findAll();
		List<com.funever.Works> cwl = new LinkedList<com.funever.Works>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		for(Works works : wl){
			com.funever.Works wks = new com.funever.Works();
			try {
				wks.setDate(sdf.parse(works.getDate()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			wks.setTypeName(works.getWorkType());
			cwl.add(wks);
		}
		cpv.workList = cwl;
		Calendar end = Calendar.getInstance();
		end.add(Calendar.MONTH, 2);
	    Calendar start = Calendar.getInstance();
	    start.add(Calendar.MONTH, -2);
		cpv.init(start.getTime(), end.getTime())
        .inMode(SelectionMode.SINGLE)
        .withSelectedDate(new Date());
		
		
	}
}
